package br.com.tiespec.ejb.Dao;

import javax.ejb.Stateless;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;

import br.com.tiespec.model.Modelo.ConfigDescricaoEstendida;

@Stateless(mappedName = "ConfigDescricaoEstendidaDAO")
public class ConfigDescricaoDAO extends DAO {

	private static final long serialVersionUID = 1L;

	public ConfigDescricaoEstendida selecionar(Long idClientePortal) {
		ConfigDescricaoEstendida cdInstance = new ConfigDescricaoEstendida();
		try {
			begin();
			cdInstance = (ConfigDescricaoEstendida) this.session.createCriteria(ConfigDescricaoEstendida.class)
					.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
					.setFetchMode("plano", FetchMode.JOIN)
					.add(Restrictions.eq("clientePortal.id", idClientePortal)).uniqueResult();
			commit();
			fecharConexao();
		} catch (Exception e){
			e.printStackTrace();
			fecharConexao();
		}
		return cdInstance;
	}
}